import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

public class Test9 {
    public static void main(String[] args) {
        DesiredCapabilities caps = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "127.0.0.1:62001");
        caps.setCapability("platformName", "Android");
        caps.setCapability("appPackage", "com.cnezsoft.xxm");
        caps.setCapability("appActivity", ".activity.MainActivity");
        caps.setCapability("noReset", true);

        AndroidDriver<MobileElement> driver = null;

        try {
            driver = new AndroidDriver<>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        // 等待喧喧加载完成
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 进入“我的”界面
        MobileElement meButton = driver.findElement(By.xpath("//android.widget.TextView[@text='我']"));
        meButton.click();

        // 退出登录
        MobileElement logoutButton = driver.findElement(By.xpath("//android.widget.TextView[@text='退出登录']"));
        logoutButton.click();
        MobileElement confirmButton = driver.findElement(By.xpath("//android.widget.Button[@text='确定']"));
        confirmButton.click();

        // 关闭连接
        driver.quit();
    }
}